package com.lei.android.videoline;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TextView;

import com.lei.android.videoline.VideoLineView.OnBarMoveListener;
import com.lei.android.videoline.VideoLineView.VideoLineDateUtils;
import com.lei.android.videoline.VideoLineView.VideoInfo;
import com.lei.android.videoline.VideoLineView.VideoLineBar;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final TextView textview = findViewById(R.id.textview);
        VideoLineBar videoLineView = findViewById(R.id.videoLineView);

        long currentTime = System.currentTimeMillis();
        textview.setText(VideoLineDateUtils.long2StringTime(currentTime, "yyyy-MM-dd HH:mm:ss"));
        videoLineView.setCurrentTimeMillis(currentTime);

        // test data
        List<VideoInfo> data = new ArrayList<>();
        data.add(new VideoInfo(VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000) + " 22:20:00", VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis() - 24 * 60 * 60 * 1000) + " 01:30:00", VideoInfo.EVENT_TYPE_STRANGER_IN));
        data.add(new VideoInfo(VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis() - 24 * 60 * 60 * 1000) + " 23:20:00", VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis()) + " 00:30:00", VideoInfo.EVENT_TYPE_RECOGNIZE_FACES));
        data.add(new VideoInfo(VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis()) + " 08:03:00", VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis()) + " 09:03:00", VideoInfo.EVENT_TYPE_STRANGER_IN));
        data.add(new VideoInfo(VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis()) + " 09:23:00", VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis()) + " 10:17:00", VideoInfo.EVENT_TYPE_RECOGNIZE_FACES));
        data.add(new VideoInfo(VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis()) + " 10:30:00", VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis()) + " 12:00:00", VideoInfo.EVENT_TYPE_MONITORING_ITEMS));
        data.add(new VideoInfo(VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis()) + " 12:15:00", VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis()) + " 13:00:00", VideoInfo.EVENT_TYPE_STRANGER_IN));
        data.add(new VideoInfo(VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis()) + " 14:00:00", VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis()) + " 16:00:00", VideoInfo.EVENT_TYPE_MONITORING_ITEMS));
        data.add(new VideoInfo(VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis()) + " 16:20:00", VideoLineDateUtils.getDateByCurrentTiem(System.currentTimeMillis()) + " 16:30:00", VideoInfo.EVENT_TYPE_RECOGNIZE_FACES));
        videoLineView.setVideoInfoList(data);

        videoLineView.setOnBarMoveListener(new OnBarMoveListener() {

            @Override
            public void onDragBar(long currentTime, VideoInfo videoInfo) {
                textview.setText(VideoLineDateUtils.long2StringTime(currentTime, "yyyy-MM-dd HH:mm:ss"));
                if (videoInfo != null) {
                    textview.setBackgroundColor(videoInfo.getEventColor());
                } else {
                    textview.setBackgroundColor(ContextCompat.getColor(getApplicationContext(),R.color.eventType));
                }
            }

            @Override
            public void onDragBarFinish(long currentTime, VideoInfo videoInfo) {

            }

            @Override
            public void onBarMoving(long currentTime, VideoInfo videoInfo) {

            }

            @Override
            public void onMaxScale() {

            }

            @Override
            public void onMinScale() {

            }
        });

    }
}
